import gi
gi.require_version("Gtk", "4.0")
from gi.repository import Gtk, GObject

class MyApp(Gtk.Application):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.builder = None

    @GObject.Signal(
        name="clicked",
        flags=GObject.SignalFlags.RUN_FIRST,
        return_type=None,
        arg_types=(GObject.TYPE_PYOBJECT,)
    )
    def on_button_clicked(self, button):
        print("Button clicked!")

    def do_activate(self):
        if self.builder is None:
            self.builder = Gtk.Builder.new_from_file("testui.ui")
            self.window = self.builder.get_object("main_window")
            self.window.set_default_size(400, 400)
            self.window.set_title("KKND")
            self.button = self.builder.get_object("my_button")
            # 修改：将信号从 'pressed' 改为 'clicked'
            self.button.connect("clicked", self.on_button_clicked)
            #self.builder.connect_signals(self)
            self.window.set_application(self)
        self.window.present()

    def do_startup(self):
      Gtk.Application.do_startup(self)

if __name__ == "__main__":
    app = MyApp(application_id="com.example.MyApp")
    app.run(None)
